<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {

	public function __construct()
	{
        parent::__construct();
       $this->load->model('m_home');
       
    }
	public function index()
	{
	  
		       
	   $this->data['subview']="v-index/v-home";
	   $this->load->view("v-index/v-index-layout",$this->data);
	}
    public function lienhe()
	{
	   //menu top
		$this->data['menutop']=$this->m_home->getmenupro();//get element
	   //	$this->data['id_menu']=$id_menu;//set id menu top panret=0
		//$this->data['cap']=$cap;
		//end menu top
	   $btn_send=$this->input->post("btn_sent");
       if($btn_send!=""){
           // echo "nut dc nhan";
            $send=$this->m_home->send_mail();
            if($send){
                $this->data['send']=1;
            }
            else{
                $this->data['send']=0;
            }
        }
	   $this->data['subview']="v-index/v-contact";
	   $this->load->view("v-index/v-index-layout",$this->data);
	}
    public function chitiet($id=NULL)
	{
	   
       //menu top
		//$this->data['menutop']=$this->m_home->getmenupro();//get element
		//$this->data['id_menu']=$id_menu;//set id menu top panret=0
		//$this->data['cap']=$cap;
		//end menu top
	   if($id==NULL)
       {
        redirect("home");
       }
       $this->data['data']=$this->m_home->getdetails($id);
       $this->data['rand']=$this->m_home->rand_item();
	   $this->data['subview']="v-index/v-details";
	  $this->load->view("v-index/v-index-layout",$this->data);
	}
    public function sanpham($id_menu,$cap,$id_slt=0,$offset=0)
	{
        $limit=3;
	    $kq=$this->m_home->sanpham($cap,$id_menu,$id_slt,$limit,$offset);
       	$this->data['data']=$kq;
        $this->data['randitem']=$this->m_home->rand_item();
		
		//phan trang
		$config['base_url'] = site_url('home/sanpham/'.$id_menu.'/'.$cap.'/'.$id_slt.'/'); // xác định trang phân trang 
		$config['total_rows'] = $kq['tt']; // xác định tổng số record 
		$config['per_page'] = $limit; // xác định số record ở mỗi trang 
		$config['uri_segment'] = 6; // xác định segment chứa page number 
		//menu top
		$this->data['menutop']=$this->m_home->getmenupro();//get element
		$this->data['id_menu']=$id_menu;//set id menu top panret=0
		$this->data['cap']=$cap;
		$this->data['id_slt']=$id_slt;
		//end menu top
		$this->pagination->initialize($config);
		
		$this->data['links'] = $this->pagination->create_links();
  
	  $this->data['subview']="v-index/v-product";
	  $this->load->view("v-index/v-index-layout",$this->data);
	}
	
	public function cat($id){
		$arr=$this->m_home->cate($id);
		var_dump($arr);
		
		}
    public function mnu($idparent=0){
        $uri=base_url("home/phanloai");
        $data=$this->m_home->cate($idparent);
        
        /*<ul class="mnu-block-product">
                <li class="dropdown"><a href="#">Phòng ngủ <b class="caret"></b></a>
                  <ul class="mnu-block-lv2">
                    <li><a href="#">tủ đầu giường</a></li>
                    <li><a href="#">giường ngủ</a></li>
                  </ul>
                </li>*/
        //var_dump($data);
        
        foreach($data as $row){
            if($row['id']!=0){
            echo '<li class="dropdown"><a href="#">'.$row['name'].'<b class="caret"></b></a>
                  <ul class="mnu-block-lv2">'.$this->sub_mnu($row['id']).'</ul></li>';
                  }
                    
        }
    }
    public function sub_mnu($idparent){
        $html="";
        $data=$this->m_home->cate($idparent);
        foreach($data as $row){
            $html.='<li><a href="#">'.$row['name'].'</a></li>';
            $html.=$this->mnu($row['id']);
        }
        return $html;
    }

	  public function search()
	{	
		$this->data['menutop']=$this->m_home->getmenupro();      
	    $this->data['subview']="v-index/v-search";
	    $this->load->view("v-index/v-index-layout",$this->data);
	}

}
?>